package com.qnbc.mystery.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qnbc.mystery.config.interceptor.AuthAccess;
import com.qnbc.mystery.core.annotation.Log;
import com.qnbc.mystery.core.controller.BaseController;
import com.qnbc.mystery.core.domain.AjaxResult;
import com.qnbc.mystery.core.enums.BusinessType;
import com.qnbc.mystery.core.utils.poi.ExcelUtil;
import com.qnbc.mystery.pojo.domain.ProArea;
import com.qnbc.mystery.pojo.response.ProAreaResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qnbc.mystery.service.IProAreaService;

/**
 * 地区码
 *
 * @author guzj
 * @date 2024-01-24
 */
@Api(tags = "地区码")
@RestController
@RequestMapping("/mystery/area")
public class ProAreaController extends BaseController {
    @Autowired
    private IProAreaService proAreaService;

    /**
     * 查询地区码列表
     */
    @GetMapping("/list")
    public AjaxResult list(ProArea proArea) {
        PageHelper.startPage(proArea.getPageNum(), proArea.getPageSize());
        List<ProArea> list = proAreaService.selectProAreaList(proArea);
        PageInfo<ProArea> pageInfo = new PageInfo<>(list);
        return AjaxResult.success(pageInfo);
    }


    /**
     * 查询地区码列表
     */
    @AuthAccess
    @ApiOperation("二级联动查询")
    @GetMapping("/erjiList")
    public AjaxResult erjiList(ProArea proArea) {
        List<ProAreaResponse> list = proAreaService.erjiList(proArea);
        return AjaxResult.success(list);
    }

    /**
     * 导出地区码列表
     */
    @Log(title = "地区码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProArea proArea) {
        List<ProArea> list = proAreaService.selectProAreaList(proArea);
        ExcelUtil<ProArea> util = new ExcelUtil<ProArea>(ProArea.class);
        util.exportExcel(response, list, "地区码数据");
    }

    /**
     * 获取地区码详细信息
     */
    @GetMapping(value = "/{areaid}")
    public AjaxResult getInfo(@PathVariable("areaid") Long areaid) {
        return AjaxResult.success(proAreaService.selectProAreaByAreaid(areaid));
    }

    /**
     * 新增地区码
     */
    @Log(title = "地区码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProArea proArea) {
        return toAjax(proAreaService.insertProArea(proArea));
    }

    /**
     * 修改地区码
     */
    @Log(title = "地区码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProArea proArea) {
        return toAjax(proAreaService.updateProArea(proArea));
    }

    /**
     * 删除地区码
     */
    @Log(title = "地区码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{areaids}")
    public AjaxResult remove(@PathVariable Long[] areaids) {
        return toAjax(proAreaService.deleteProAreaByAreaids(areaids));
    }
}
